home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 038a / bas_int1.zip / _ISFILE.BAS < prev    next >
BASIC Source File  |  1991-06-02  |  1KB  |  41 lines

  1. '==================================================================
  2. ' Quick Basic Forum
  3. '   Date : 28-May-91
  4. '   From : Rick Cooper
  5. 'Subject : File handling (Open error)
  6. '           Uses CALL INTERRUPT; be sure to INCLUDE 'QB.BI'
  7. '           and use appropriate libraries containing
  8. '           CALL INTERRUPT
  9. '=================================================================
  10.  
  11. 'sample main program code using FUNCTION FileExist%
  12. DECLARE FUNCTION FileExist% (FileName$)
  13. '$INCLUDE: 'Qb.bi'
  14. FileName$ = "ANYFILE.INP"
  15. InFile% = FREEFILE
  16. IF FileExist%(FileName$) THEN
  17.         OPEN FileName$ For INPUT AS #InFile%
  18. ELSE
  19.         WhatEverYouWant
  20. END IF
  21.  
  22. 'Here's the FUNCTION
  23. FUNCTION FileExist% (FileName$)
  24.  
  25. DIM InRegsX AS RegTypeX, OutRegsX AS RegTypeX   'Dim The Registers
  26.  
  27. FileToSet$ = FileName$ + CHR$(0)                'We Use The Fast Small
  28. InRegsX.ax = (256 * &H43) + &H0                 'Get File Attribute
  29. InRegsX.ds = VARSEG(FileToSet$)                 'Function. If Carry Flag
  30. InRegsX.dx = SADD(FileToSet$)                   'Is Set Error Otherwise
  31. CALL INTERRUPTX(&H21, InRegsX, OutRegsX)        'File And Drive/Path Valid
  32.  
  33. IF (OutRegsX.flags AND 1) <> 0 THEN
  34.         FileExist% = 0                          'If Error File Doesn't Exist
  35. ELSE
  36.         FileExist% = 1                          'OtherWise Set To Non Zero
  37. END IF
  38.  
  39. END FUNCTION
  40.  
  41.